package com.base.home.adapter;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.recy.BaseHolderType;
import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.home.HomeConfig;
import com.base.home.R;
import com.base.home.bean.ConcertSelectEntity;
import com.base.home.databinding.ItemCoursewareBinding;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;


/**
 * 精选课程
 *
 * @version V1.0 <描述当前版本功能>
 *          Created by admin on 2018/5/22.
 * @FileName: com.zhongyue.mdchengguan.ui.main.adapter.CategoryViewHolder.java
 * Author weikailiang
 * @date: 2018-05-22 14:22
 */
public class CourViewHolder extends BaseHolderType<ConcertSelectEntity.RecentLearnBean,CourViewHolder.CoursViewHolder> {

    @Override
    public int getType(ConcertSelectEntity.RecentLearnBean beans) {
        return HomeConfig.COURSEWARE;
    }

    @Override
    public void bindDataToHolder(final CoursViewHolder holder, final ConcertSelectEntity.RecentLearnBean bean, int postion) {
        holder.mBinding.courseTitle.setText(bean.getName());
        holder.mBinding.courseIntro.setText(bean.getCreateUserName()==null?"":"作者:"+bean.getCreateUserName());
        holder.mBinding.courseTime.setText(bean.getCreateDate());
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.ic_empty)
                .error(R.drawable.ic_empty)
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        Glide.with(holder.mBinding.coursePhoto.getContext())
                .load(bean.getCover())
                .apply(options)
                .into(holder.mBinding.coursePhoto);
        holder.mBinding.courseCardview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build("/curriculum/detail").withString("id",bean.getId())
                        .withString("url",bean.getCover()).navigation();
            }
        });
    }



    @Override
    public CoursViewHolder buildHolder(ViewGroup parent) {
        return new CoursViewHolder(View.inflate(parent.getContext(), R.layout.item_courseware, null));
    }



    public static class CoursViewHolder extends BasicRecyViewHolder {
        private ItemCoursewareBinding mBinding;
        public CoursViewHolder(View itemView) {
            this(itemView, null, null);
            mBinding = DataBindingUtil.bind(itemView);
        }
        public CoursViewHolder(View itemView, OnItemClickListener clickListener, OnItemLongClickListener longClickListener) {
            super(itemView, clickListener, longClickListener);
        }
    }
}
